package com.aistar.controller;

import com.aistar.pojo.ClubActivity;
import com.aistar.service.ActivityReleaseService;
import com.aistar.util.DateUtil;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.stereotype.Controller;

import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;


import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

@Controller
public class ActivityReleaseController {
    @Autowired
    public ActivityReleaseService activityReleaseService;

    //发布新活动
    @RequestMapping(value = "/write/activivity")
    public void saveNewActivity(HttpServletRequest request, HttpServletResponse response){
        //将网页数据都上传到数据库
        ClubActivity clubActivity=new ClubActivity();
        //接收前端的参数
        String clubName=request.getParameter("clubName");//获得俱乐部活动标题
        clubActivity.setClubName(clubName);

        System.out.println(clubName);   //测试前端数据是否接收到了

        String clubLocation=request.getParameter("clubLocation"); //活动地点
        clubActivity.setClubLocation(clubLocation);
        System.out.println(clubLocation);

        String clubTheme=request.getParameter("clubTheme");   //文本域里面的数据
        clubActivity.setClubTheme(clubTheme);
        System.out.println(clubTheme);

        Float clubPrice=Float.valueOf(request.getParameter("clubPrice")); //活动参加费用
        clubActivity.setClubPrice(clubPrice);
        System.out.println(clubPrice);


        String cbtime=request.getParameter("clubBaoming");  //报名时间
        String cbStarttime  =cbtime.substring(0,10);
        String cbEndtime=cbtime.substring(13,23);
        System.out.println(cbStarttime+cbEndtime);

        //将String类型转换成Date类型
        Date startdate= DateUtil.stringToDate(cbStarttime,DateUtil.PATTERN_YMD);
        clubActivity.setClubStart(startdate);
        //结束时间
        Date enddate=DateUtil.stringToDate(cbEndtime,DateUtil.PATTERN_YMD);
        clubActivity.setClubEnd(enddate);



        String  cdtime=request.getParameter("clubHuodong");  //活动时间
        String cbBegintime  =cbtime.substring(0,10);
        String cbFinishtime=cbtime.substring(13,23);
        System.out.println(cbBegintime+cbBegintime);
        //将String类型转换成字符串
        Date begindate=DateUtil.stringToDate(cbBegintime,DateUtil.PATTERN_YMD);
        clubActivity.setClubBegin(begindate);

        Date finishdate=DateUtil.stringToDate(cbFinishtime,DateUtil.PATTERN_YMD);
        clubActivity.setClubFinish(finishdate);

        String picture = request.getParameter("img");//活动图片
        clubActivity.setClubOther1(picture);
        System.out.println(picture);




        activityReleaseService.saveActivity(clubActivity);

    }






}
